<template>
    <span>
        <Button type="error" size="small" @click="handleClientDelete(data)" icon="ios-trash" title="删除"></Button>
    </span>
</template>

<script>
import { mapMutations } from 'vuex';

export default {
    name: "ClientDeleteButton",
    props: {
        data: Object
    },
    methods: {
        ...mapMutations(['removeClientBriefKey']),
        handleClientDelete(row) {
            this.$Modal.confirm({
                title: '删除',
                content: '确定删除吗？',
                onOk: () => {
                    this.$http.post('/delete_client', { id: row.id }).then((res) => {
                        if (res.status == 'ok') {
                            this.$Message.success('删除成功');
                            this.removeClientBriefKey(row.client_id);
                            this.$emit('success');
                        } else {
                            this.$Message.error(res.data);
                        }
                    });
                },
                onCancel: () => {
                    this.$Message.info('取消删除');
                }
            });
        },
    }
}
</script>